package org.example.shop.util;

import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class UserUtil {
    public static void checkLogin() {
        // 活到去请求对象
        HttpServletRequest req = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes()))
                .getRequest();
        String token = req.getHeader("token");
        if(StringUtils.isEmpty(token)){
            throw new RuntimeException("need login");
        }
        // 查询token是否有绑定的用户信息
        if(!token.equals("test")){//模拟一个
            throw new RuntimeException("need login");
        }
    }
}
